/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.awt.CardLayout;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import tools.Configuration;

/**
 *
 * @author ayle
 */
public class MainWindow extends javax.swing.JFrame {

    private Background background;
    UsersPanel usersPanel;
    BackgroundPanel backPanel;
    AddUserPanel adduserPanel;

    /* Creates new background image */
    private void NewBackground() {
        try {
            File file = new File(Configuration.getInstance().getProperty(Configuration.PATH_BACKGROUND_IMAGE));
            BufferedImage tmpImg = ImageIO.read(file);
            background = new Background(tmpImg);
        } catch (IOException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Creates new form MainWindow
     */
    public MainWindow() {
        NewBackground();
        usersPanel = new UsersPanel();
        backPanel = new BackgroundPanel();
        adduserPanel = new AddUserPanel();
        initComponents();
        AdminTool_Panel.add(usersPanel, "ListUsers");
        AdminTool_Panel.add(backPanel, "Background");
        AdminTool_Panel.add(adduserPanel, "AddUsers");
        CardLayout cardLayout = (CardLayout) AdminTool_Panel.getLayout();
        cardLayout.show(AdminTool_Panel, "Background");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        AdminTool_Panel = new javax.swing.JPanel();
        MenuBar = new javax.swing.JMenuBar();
        FileMenu = new javax.swing.JMenu();
        ListUsers = new javax.swing.JMenuItem();
        AddUsers = new javax.swing.JMenuItem();
        Close = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("ROBBIE@admin");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setMaximumSize(new java.awt.Dimension(400, 300));
        setMinimumSize(new java.awt.Dimension(400, 300));
        setPreferredSize(new java.awt.Dimension(400, 300));
        setResizable(false);

        AdminTool_Panel.setBorder(background);
        AdminTool_Panel.setMaximumSize(new java.awt.Dimension(400, 281));
        AdminTool_Panel.setMinimumSize(new java.awt.Dimension(400, 281));
        AdminTool_Panel.setPreferredSize(new java.awt.Dimension(400, 281));
        AdminTool_Panel.setLayout(new java.awt.CardLayout());

        FileMenu.setText("File");

        ListUsers.setText("Users");
        ListUsers.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ListUsersActionPerformed(evt);
            }
        });
        FileMenu.add(ListUsers);

        AddUsers.setText("Add User");
        AddUsers.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddUsersActionPerformed(evt);
            }
        });
        FileMenu.add(AddUsers);

        Close.setText("Close");
        Close.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CloseActionPerformed(evt);
            }
        });
        FileMenu.add(Close);

        MenuBar.add(FileMenu);

        setJMenuBar(MenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(AdminTool_Panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(AdminTool_Panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ListUsersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ListUsersActionPerformed
        CardLayout cardLayout = (CardLayout) AdminTool_Panel.getLayout();
        cardLayout.show(AdminTool_Panel, "ListUsers");
    }//GEN-LAST:event_ListUsersActionPerformed

    private void CloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CloseActionPerformed
        System.exit(0);
    }//GEN-LAST:event_CloseActionPerformed

    private void AddUsersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddUsersActionPerformed
        CardLayout cardLayout = (CardLayout) AdminTool_Panel.getLayout();
        cardLayout.show(AdminTool_Panel, "AddUsers");
    }//GEN-LAST:event_AddUsersActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new MainWindow().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem AddUsers;
    private javax.swing.JPanel AdminTool_Panel;
    private javax.swing.JMenuItem Close;
    private javax.swing.JMenu FileMenu;
    private javax.swing.JMenuItem ListUsers;
    private javax.swing.JMenuBar MenuBar;
    // End of variables declaration//GEN-END:variables
}
